package manager

import (
	"github.com/gin-gonic/gin"
	"tadmin/models/dto"
	"tadmin/pkg/ginx"
	"tadmin/service"
)

var workerService = &service.WorkerService{}

type WorkerApi struct{}

func (w *WorkerApi) Add(c *gin.Context) {
	var addDto dto.WorkerAddDto
	c.ShouldBindJSON(&addDto)
	err := workerService.Add(addDto)
	ginx.Result(c, nil, err)
}

func (w *WorkerApi) Delete(c *gin.Context) {
	var idInfoDto ginx.IdInfoDto
	c.ShouldBindJSON(&idInfoDto)

	err := workerService.Delete(idInfoDto.Id)
	if err != nil {
		ginx.ResFail(c, err.Error())
	} else {
		ginx.ResSuccess(c, nil)
	}
}

func (w *WorkerApi) Query(c *gin.Context) {
	var queryDto dto.WorkerQueryDto
	c.ShouldBindJSON(&queryDto)
	list, total, err := workerService.PageQuery(queryDto)
	ginx.Result(c, gin.H{
		"list":       list,
		"totalCount": total,
	}, err)
}

func (w *WorkerApi) WorkPlaceList(c *gin.Context) {
	list, err := workerService.ListWorkPlace()
	ginx.Result(c, gin.H{
		"list": list,
	}, err)
}
